from src.data import DataSeq
import time

def ShellSort(ds,v):
    assert isinstance(ds, DataSeq), "Type Error"
    Length = ds.length
    D = Length // 2
    while D > 0:
        i = 0
        while i < Length:
            tmp = ds.data[i]

            j = i
            while j >= 1 and ds.data[j - D] > tmp:
                ds.SetVal(j, ds.data[j - D])
                j -= D
            ds.SetVal(j, tmp)

            i += D
        D //= 2
        time.sleep(v)


def create_sort(title, v, l):
    ds = DataSeq(l, sort_title=title)
    ds.Visualize()
    ds.StartTimer()
    ShellSort(ds, v)
    ds.StopTimer()
    ds.SetTimeInterval(0)
    # ds.Visualize()
    time.sleep(3)
    ds.destory()
    return 0


if __name__ == "__main__":
    ds = DataSeq(64)
    ds.Visualize()
    ds.StartTimer()
    ShellSort(ds)
    ds.StopTimer()
    ds.SetTimeInterval(0)
    ds.Visualize()
